package com.hzj.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzj.pojo.Department;
import com.hzj.service.DepartmentService;
import com.hzj.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hzj
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/provider/admin/hosp/department")

public class DepartmentController {
    @Autowired
    DepartmentService ds;

    @PostMapping("/getDeptList/{hoscode}")
    Result getDeptList(@PathVariable String hoscode) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("hoscode", hoscode);
        wrapper.groupBy("bigname");
        List<Department> list = ds.list(wrapper);
        List<Map<String, Object>> listAll = new ArrayList();
        for (Department department : list) {
            Map map = new HashMap();
            map.put("depname", department.getBigname());
            QueryWrapper wrapper1 = new QueryWrapper();
            wrapper1.eq("bigname", department.getBigname());
            map.put("children", ds.list(wrapper1));
            listAll.add(map);
        }


        return Result.ok(listAll);


    }

}

